<?php
	
	$session=session_id();
	$time=time();
	$time_check=$time-600;
	
	$query = mysql_query(" SELECT session_id FROM user_online WHERE session_id = '{$session}' ");	
	
	$q = mysql_query(" SELECT id,view FROM total_visit WHERE view != '' ");
	$row = mysql_fetch_array($q);
	$total = $row['view'] == "" ? 0 : $row['view'];
	$id = $row['id'];
	
	if(mysql_num_rows($query) > 0)
		mysql_query(" UPDATE user_online SET time = {$time} WHERE session_id = '{$session}' ");
	else
	{	
		mysql_query(" INSERT INTO user_online(session_id,time) VALUES('{$session}', {$time}) ");
		
		if(mysql_num_rows($q) == 0)
		{
			$total = 1;
			mysql_query(" INSERT INTO total_visit(view) VALUES('{$total}') ");
		}
		$total = $total + 1;
		mysql_query(" UPDATE total_visit SET view = {$total} WHERE id = {$id} ");
	}
	
	$query1 = mysql_query(" SELECT * FROM user_online WHERE session_id != '' ");
	$user_online = mysql_num_rows($query1);
	
	$res = mysql_fetch_array(mysql_query(" SELECT view FROM total_visit WHERE view != '' "));
	$count = $res['view'];
	
	echo "	<p style='margin:5px 0px 3px 10px;font-size:16px;text-shadow:2px 2px 5px #fff;'> 
		      <span style='color:#00f;font-weight:bold; font-size:18px;'> >> </span> Số người đang Online:<strong> $user_online </strong>
			</p>";
	echo "	<p style='margin:5px 0px 3px 10px;font-size:16px;text-shadow:2px 2px 5px #fff;'>
		   <span style='color:#00f;font-weight:bold; font-size:18px;'> >> </span>Tổng lượt truy cập:<strong> $count </strong>
			</p>";
	
	
	mysql_query(" DELETE FROM user_online WHERE time < '{$time_check}' ");

?>